package com.sczmgk.hotline_pzh.utils;

import android.annotation.SuppressLint;
import android.os.Environment;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
 *将Log这写入文件,
 * @author Administrator
 *
 */
public class LogFile {

	private static boolean isWrite = false;
	public static String FilePath = Environment.getExternalStorageDirectory()+"/lezheng/";
	public static String LogFilePath = FilePath+"/log/";
	@SuppressLint("SimpleDateFormat")
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static void writeLog(String action,String fileName)
	{

		if(isWrite)
		{
			File file1 = new File(LogFilePath);
			if(!file1.exists())
			{
				file1.mkdirs();
			}
			File file = new File(LogFilePath, fileName);

			Calendar c = Calendar.getInstance();
			c.setTimeInMillis(System.currentTimeMillis());
			String date = sdf.format(c.getTime());
			try {
				FileWriter fileWriter = new FileWriter(file, true);
				BufferedWriter bufWriter = new BufferedWriter(fileWriter);
				bufWriter.write(date+"-->"+action);
				bufWriter.write("\r\n");
				bufWriter.close();
				fileWriter.close();
			} catch (Exception e) {
				
			}
		}
	}
}
